//Focus on (Creating,Reading,Deleting,Renaming) Files

//1.Load file system
const fs = require('fs');
//2.create a file
fs.writeFile('File Name.txt',"this is an example",(err)=>{
    if(err) console.log(err);
    else console.log('File successfully created by 4.WorkingWithFileSystemModule.js');
});
//3.read from a file
fs.readFile('File Name.txt',(err,file)=>{
    if(err) console.log(err);
    else console.log(file);//<Buffer 74 68 69 73 20 69 73 20 61 6e 20 65 78 61 6d 70 6c 65>
});
fs.readFile('File Name.txt','utf8',(err,file)=>{
    if(err) console.log(err);
    else console.log('utf8: '+file);//utf8: this is an example
});
//4.rename a file
fs.rename('File Name.txt','New File Name.txt',(err)=>{
    if(err) console.log(err);
    else console.log('Successfully renamed the file.');
});
//5.append to a file
fs.appendFile('New File Name.txt','\nSome data being appended',(err)=>{
    if(err) console.log(err);
    else console.log('Successfully appended data to the file.');
});
//6.delete a file
fs.unlink('New File Name.txt',(err)=>{
    if(err) console.log(err);
    else console.log('Successfully deleted the file.');
});